package selef.xiafan.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import selef.xiafan.entity.system.Category;
import selef.xiafan.query.CategoryQuery;
import selef.xiafan.service.ICategoryService;
import selef.xiafan.util.result.PageResult;
import selef.xiafan.util.result.Result;
import selef.xiafan.util.result.ResultFactory;

/**
 * @author xiafan
 * @version 1.0
 * @date 2021/9/15 9:10
 */
@RestController
@RequestMapping("/api/category")
public class CategoryController {
    @Autowired
    ICategoryService iCategoryService;

    @PostMapping("/queryPage")
    public PageResult categoryPageList(@RequestBody CategoryQuery categoryQuery){
        return iCategoryService.queryPage(categoryQuery);
    }
    @PostMapping("/add_update")
    public Result AddOrUpdate(@RequestBody Category category){
        Integer result = iCategoryService.AddOrUpdate(category);
        if(result==1)
            return ResultFactory.buildSuccessResult("添加成功");
        if(result==2)
            return ResultFactory.buildSuccessResult("修改成功");
        return ResultFactory.buildFailResult("操作异常");
    }
    @PostMapping("/deleteOne")
    public Result deletOne(@RequestBody Category category){
        Integer result = iCategoryService.deleteOne(category);
        if(result ==1){
            return ResultFactory.buildSuccessResult(category.getName()+"删除成功");
        }
        return ResultFactory.buildFailResult("操作异常");
    }}
